<?php
$masterView = MasterView::getInstance();
?>
<?php
foreach ($masterView->folderView->folders as $folder) :
    $streams = StreamController::getStream($folder->folderId);
    ?>
    <li>
        <a folderid='<?php echo $folder->folderId; ?>' class="expand-folder <?php echo (count($streams) + count($folder->child) > 0 ? "" : "folder-fade"); ?>">
            <i class="fa fa-folder-open"></i>
            <i class="fa fa-folder"></i><?php echo $folder->folderName; ?>
        </a>
        <ul>
        <?php
            if (count($folder->child) > 0) {
                foreach ($folder->child as $childFolder) :
                    $childStreams = StreamController::getStream($childFolder->folderId);
                    ?>
                    <li>
                        <a parentid='<?php echo $folder->folderId; ?>' class="expand-folder <?php echo (count($childStreams) > 0 ? "" : "folder-fade"); ?>">
                            <i class="fa fa-folder-open"></i>
                            <i class="fa fa-folder"></i><?php echo $childFolder->folderName; ?>
                        </a>
                        <ul>
                            <?php
                            if (count($childStreams) > 0) {
                                foreach ($childStreams as $stream):
                                ?>
                                <li>
                                    <a parentid='<?php echo $folder->folderId; ?>' streamid="<?php echo $stream->streamId; ?>" href="/#metrics/<?php echo base64_encode($stream->streamId); ?>"><i class="ub ub-stream"></i><?php echo $stream->name; ?></a>
                                </li>
                            <?php endforeach; 
                            }
                            ?>
                        </ul>
                    </li>
                <?php endforeach;
            }
            if (count($streams) > 0) {
                foreach ($streams as $stream):
            ?>
                <li>
                    <a streamid="<?php echo $stream->streamId; ?>" href="/#metrics/<?php echo base64_encode($stream->streamId); ?>"><i class="ub ub-stream"></i><?php echo $stream->name; ?></a>
                </li>
            <?php endforeach; 
            }
            ?>
        </ul>
    </li>            
    <span class="separator"></span>
<?php endforeach;